package pl.pr3sto.security

import grails.test.*

class ProfileControllerTests extends ControllerUnitTestCase {
    protected void setUp() {
        super.setUp()
		mockDomain(Profile)
    }

    void testAuthenticationBarSessionEmpty() {
		// given
		Profile.metaClass.'static'.getGuest = {
			return new Profile(role: Role.GUEST)
		}
		assert controller.session.profile == null
		
		// when
		def result = controller.authenticationBar()
		
		// then
		assert controller.session.profile.role == Role.GUEST
		assert result.profile.role == Role.GUEST
    }
	
	void testAuthenticationBarUserLoggedIn() {
		// given
		controller.session.profile = new Profile(role: Role.ADMIN)
		
		// when
		def result = controller.authenticationBar()
		
		// then
		assert controller.session.profile.role == Role.ADMIN
	}
}
